<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/theme/bootstrap.css" />
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/js/bootstrap/css/bootstrap-table.min.css" />
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/theme/bootstrap-responsive.css" /> 
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/theme/style.css" />
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-1.11.3.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/theme/bootstrap.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/bootstrap/bootstrap-table.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/bootstrap/bootstrap-table-locale-all.min.js"></script> 
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/layerui/layer.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/layerui/layer.ext.js"></script>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/skin/css/mobilecss/charge.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/skin/css/mobilecss/main.css">
    
    <style type="text/css">
        body {
            padding-bottom: 40px;
        }
        .sidebar-nav {
            padding: 9px 0;
        }

        @media (max-width: 980px) {
            /* Enable use of floated navbar text */
            .navbar-text.pull-right {
                float: none;
                padding-left: 5px;
                padding-right: 5px;
            }
        }
    </style>
</head>
<body>

<div class="alert" id="alertDivId" style="display: none;z-index: 100; padding-right: 5px;padding-top: 0px;">
        <div >
            <p>昵称：<span id="niceName"></span></p>
            <p>游戏ID：<span id="gameId"></span></p>
            <p>绑定：<input style="width: 128px" id="agentId" type="text"></p>
            <input type="hidden" id="user_Id" name="user_Id" >
            <div>
                <button id="ok" onclick="confirmAgentClick()">确认绑定</button>
                <button style="background-color: #666;margin-left: 5%" id="close" onclick="closeAlertClick()">取消</button>
            </div>
        </div>
    </div>

<form class="form-inline definewidth m20" action="index.html" method="get">  
    <input type="text" name="phone" id="phone" placeholder="手机号搜索" value=""  style="width: 130px;height: 35px">
    <select  id="status" name="status" placeholder="用户状态搜索"  style="width: 135px;height: 39px;display: none;" > 
    	<option value="" selected="selected">全部</option>
   		<option value="0" selected="selected">未激活</option>
   		<option value="1">已激活</option>
    </select>
    
    <button type="button" onclick="query()" class="btn btn-primary">查询</button>
</form>
 <table id="mytab" class="table table-striped table-bordered"></table>  <br>
</body>
<script>
	
	function query() {
	    var phone = $('#phone').val();
	    var status = $('#status option:selected').val();
	    $('#mytab').bootstrapTable("refreshOptions", {
	        queryParams: function (params) {
	            params.numPerPage = params.limit;
	            params.pageNum = params.offset / params.limit + 1;
	            params.phone = phone;
	            params.status = status;
	            return params;
	        }
	    });
	    $('#mytab').bootstrapTable({
	        url: "${pageContext.request.contextPath}/admin/user_list_data.html", //数据源
	       // height:tableHeight(),
	        dataField: "rows", //服务端返回数据键值 就是说记录放的键值是rows，分页时使用总记录数的键值为total
	        pagination: true, //是否分页
	        pageSize: 10, //单页记录数
	        pageList : [10,20,50,100,200 ],//分页步进值
	        sidePagination: "server", //服务端分页
	        contentType: "application/x-www-form-urlencoded", //请求数据内容格式 默认是 application/json 自己根据格式自行服务端处理
	        dataType: "json", //期待返回数据类型
	        method: "post", //请求方式
	        searchAlign: "left", //查询框对齐方式
	        locale: "zh-CN",
	        queryParams: function (params) {
	                params.numPerPage = params.limit;
	                params.pageNum = params.offset / params.limit + 1;
	                params.phone = phone;
	                params.status = status;
	                return params;
	            },
	            buttonsAlign: "left", //按钮对齐方式
	            paginationHAlign:"left",
	        columns: [{
	        	width: "10%",
	            field: "id",
	            title: "操作",
	            formatter: function (value, row, index) {
	            	var html ="";
	            	if(row.status==0){
	            		html += '<a href="javascript:;" onclick="setStatus('+value+','+1+')" >激活</a>';
	            	}if(row.status==2||row.status==3){
	            		html += '<a href="javascript:;" onclick="setStatus('+value+','+1+')" >解封</a>';
	            	}else if(row.status==1){
	            		html += '<a href="${pageContext.request.contextPath}/admin/card_user_add_mobile.html?userId='+value+'" >充卡</a><br>';
	            		html += '<a href="${pageContext.request.contextPath}/admin/tradeFlow_edit_mobile.html?userId='+value+'" >打款</a><br>';
	            		
	            	}
	                return html ;
	            }
	        }, {
	            field: "phone",
	            title: "手机号",
	        }, {
	            field: "userName",
	            title: "昵称",
	        },{
	            field: "gameUserId",
	            title: "游戏ID",
	        },{
	            field: "outUserId",
	            title: "微信号",
	        },{
	            field: "myAgentTotals",
	            title: "下级<br>人数",
	        },{
	            field: "totalCard",
	            title: "剩余<br>房卡",
	        },{
	            field: "ticeng",
	            title: "提成",
	        },{
	            field: "remark",
	            title: "备注",
	        }
	        ,{
	        	width: "10%",
	            field: "status",
	            title: "状态",
	            formatter: function (value, row, index) {
	            	var html = '其他';
	            	if(row.status==0){
	            		html = '未激活';
	            	}else if(row.status==1){
	            		html = '正常';
	            	}else if(row.status==2){
	            		html = '已注销';
	            	}else if(row.status==3){
	            		html = '已删除';
	            	}
	                return html ;
	            }
	        },{
	            field: "createTime",
	            title: "加入时间",
	        },{
	        	width: "10%",
	            field: "id",
	            title: "绑定靓号",
	            formatter: function (value, row, index) {
	            	var html = '';
	            	html += '<a href="javascript:;" onclick="setAgentId(\''+value+'\',\''+row.userName+'\',\''+row.gameUserId+'\')" >绑定: '+row.agentId+'</a>';
	                return html ;
	            }
	        },{
	        	width: "10%",
	            field: "id",
	            title: "密码找回",
	            formatter: function (value, row, index) {
	            	var html = '';
	            	html += '<a href="javascript:;" onclick="setPassword('+value+',\''+row.userName+'\')" >初始化<br>密码</a>';
	            	html += '<a href="javascript:;" onclick="setStatus('+value+','+2+')" ><br>封禁用户</a>';
	                return html ;
	            }
	        }]
	    }).on("click-row.bs.table", function (args, row, $element) {
	        
    });}
	
	
	  function setStatus(userId,status){
	    	var msg = (status==1?"激活":"封禁") +" 该用户 ？";
	    	layer.confirm('确认'+msg, {
	    	    btn: ['确认','取消'], //按钮
	    	    shade: false //不显示遮罩
	    	}, function(){
	    	    $.post("${pageContext.request.contextPath}/admin/user_list_status.html",
	    	            {"userId":userId,"status":status},
	    	       function(data){
	    	            	var json = eval("("+data+")");
	    	            	$('#usersave').removeAttr("disabled");  //移除disabled属性 
	    					if(json.statusCode =='200'){
	    						layer.msg(json.message, {icon: 1});
	    						setTimeout("query()",2000);
	    					}else{
		    					layer.msg(json.message, {shift: 6});
	    					}
	    	      });
	    	});
	   }
	  
	  function setPassword(userId,nikeName){
	    	var msg = "确认初始化用户  [ "+nikeName+" ] 的密码 ？<br> 初始化后密码为123456 ";
	    	layer.confirm(msg, {
	    	    btn: ['确认','取消'], //按钮
	    	    shade: false //不显示遮罩
	    	}, function(){
	    	    $.post("${pageContext.request.contextPath}/admin/user_edit_password.html",
	    	            {"userId":userId},
	    	       function(data){
	    	            	var json = eval("("+data+")");
	    	            	$('#usersave').removeAttr("disabled");  //移除disabled属性 
	    					if(json.statusCode =='200'){
	    						layer.msg(json.message, {icon: 1});
	    						setTimeout("query()",2000);
	    					}else{
		    					layer.msg(json.message, {shift: 6});
	    					}
	    	      });
	    	});
	   }
	  
	  // 设置靓号
	  function setAgentId(userId,nikeName,gameId){
  		$("#niceName").html(nikeName);
  		$("#gameId").html(gameId);
  		$("#user_Id").val(userId);
		$(".alert").css('display', 'block');
	  }
	  
	  function confirmAgentClick(){
		  var msg = "确认设置用户  [ "+$("#niceName").html()+" ] 的靓号为 "+$("#agentId").val()+"？ ";
	    	layer.confirm(msg, {
	    	    btn: ['确认','取消'], //按钮
	    	    shade: false //不显示遮罩
	    	}, function(){
	    	    $.post("${pageContext.request.contextPath}/admin/user_edit_agentId.html",
	    	            {"userId":$("#user_Id").val(),"agentId":$("#agentId").val()},
	    	       function(data){
	    	            	var json = eval("("+data+")");
	    	            	$('#usersave').removeAttr("disabled");  //移除disabled属性 
	    					if(json.statusCode =='200'){
	    						layer.msg(json.message , {icon: 1});
	    						$('.alert').css('display', 'none');
	    						setTimeout("query()",2000);
	    					}else{
		    					layer.msg(json.message, {shift: 6});
	    					}
	    	      });
	    	});
		  
	  }
	  
	  function closeAlertClick() {
			$('.alert').css('display', 'none');
	  }
	  
    $(function () {
    	query();
    	
    });

</script>
</html>